package com.zmn.plat.services.impl.base.servicecontent;

import com.zmn.account.common.utils.NumberUtil;
import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.base.servicecontent.ServiceContent;
import com.zmn.plat.model.entity.base.servicecontent.ServiceContentQuery;
import com.zmn.plat.persistence.interfaces.base.servicecontent.ServiceContentDao;
import com.zmn.plat.services.interfaces.base.servicecontent.ServiceContentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 服务内容接口实现类
 *
 * @author fengxuecai
 * @since  2021/11/17 14:19
 */
@Slf4j
@Service
public class ServiceContentServiceImpl implements ServiceContentService {

    private static final String TAG = "服务内容基础服务接口";

    @Resource
    private ServiceContentDao serviceContentDao;

    @Override
    public ServiceContent findById(Integer servId) {

        if (NumberUtil.isNullOrZero(servId)) {
            log.error("[{}],根据id查询数据servId为null", TAG);
            return null;
        }
        return serviceContentDao.findById(servId);
    }

    @Override
    public Integer findMaxSort() {
        return serviceContentDao.findMaxSort();
    }

    @Override
    public List<ServiceContent> listByIds(List<Integer> servIds) {

        if (CollectionUtils.isEmpty(servIds)) {
            log.error("[{}],按条件查询数据,servIds为null", TAG);
            return null;
        }
        return serviceContentDao.listByIds(servIds);
    }

    @Override
    public List<ServiceContent> listByQuery(ServiceContentQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return serviceContentDao.listByQuery(query);
    }

    @Override
    public List<ServiceContent> listPageByQuery(ServiceContentQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        query.setTotalCount(countByQuery(query));
        return serviceContentDao.listPageByQuery(query);
    }

    @Override
    public Integer countByQuery(ServiceContentQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return serviceContentDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(ServiceContent baseServiceItem) {

        if (Objects.isNull(baseServiceItem.getServId())){
            log.error("[{}],根据id修改数据,baseServiceItem为null", TAG);
            return null;
        }
        return serviceContentDao.updateByKey(baseServiceItem);
    }

    @Override
    public void updateStatusBatch(List<Integer> ids, Integer status, String operator) {

        if (!Objects.equals(status, GlobalConsts.NO) && !Objects.equals(status, GlobalConsts.YES)) {
            log.error("[{}],status状态超出取值范围", TAG);
            return;
        }
        serviceContentDao.updateStatusBatch(ids, status, operator, DateUtil.getNow());
    }

    @Override
    public Integer insert(ServiceContent baseServiceItem){

        if (Objects.isNull(baseServiceItem)){
            log.error("[{}],新增数据,baseServiceItem为null", TAG);
            return null;
        }
        return serviceContentDao.insert(baseServiceItem);
    }

    @Override
    public void insertBatch(List<ServiceContent> list){

        if (CollectionUtils.isEmpty(list)) {
            log.error("[{}],数据为空", TAG);
            return;
        }
        serviceContentDao.insertBatch(list);
    }

    @Override
    public void insertBatchExport(List<ServiceContent> list){

        if (CollectionUtils.isEmpty(list)) {
            log.error("[{}],数据为空", TAG);
            return;
        }
        serviceContentDao.insertBatchExport(list);
    }

    @Override
    public Integer deleteByKey(Integer servId) {

        if (Objects.isNull(servId)){
            log.error("[{}],根据id删除数据,servId为null", TAG);
            return null;
        }
        return serviceContentDao.deleteByKey(servId);
    }

}